package com.article.service.Impl;

import com.article.entity.dto.SearchNoticeTypeDao;
import com.article.entity.pojo.NoticeType;
import com.article.mapper.NoticeTypeMapper;
import com.article.service.NoticeTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;


@Service
public class NoticeTypeServiceImpl extends ServiceImpl<NoticeTypeMapper, NoticeType> implements NoticeTypeService {


    @Autowired
    private NoticeTypeMapper noticeTypeMapper;

    @Override
    public List<NoticeType> getArticleType(int page, int limit) {
        int pageStart = (page - 1) * limit;
        return noticeTypeMapper.getNoticeType(pageStart, limit);
    }

    @Override
    public int selectNoticeTypeNumber() {
        return noticeTypeMapper.selectNoticeTypeNumber();
    }

    @Override
    public List<NoticeType> searchNoticeType(SearchNoticeTypeDao searchNoticeTypeDao) {
        return noticeTypeMapper.searchNoticeType(searchNoticeTypeDao);
    }

    @Override
    public int selectNoticeTypeNumber(SearchNoticeTypeDao searchNoticeTypeDao) {
        return noticeTypeMapper.selectNoticeTypeNumber(searchNoticeTypeDao);
    }

    @Override
    public int addNoticeType(NoticeType noticeType) {
        NoticeType notice = noticeTypeMapper.getNotice(noticeType.getName(), noticeType.getType());
        if (notice != null) {
            return 0;
        }
        noticeType.setCreateTime(LocalDate.now().toString());
        return noticeTypeMapper.addNoticeType(noticeType);
    }

    @Override
    public int updateNoticeType(NoticeType noticeType) {
        noticeType.setCreateTime(LocalDate.now().toString());
        return noticeTypeMapper.updateNoticeType(noticeType);
    }

    @Override
    public int deleteNoticeType(int id) {
        return noticeTypeMapper.deleteById(id);
    }

    @Override
    public int deleteNoticeTypes(List<Integer> ids) {
        return noticeTypeMapper.deleteBatchIds(ids);
    }

    @Override
    public int updateNoticeTypeStatus(int id, Boolean status) {
        return noticeTypeMapper.updateNoticeTypeStatus(id, status);
    }


}
